package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class addOperation implements Ioperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("添加书籍！");
        System.out.println("请输入你要添加的书籍信息：");
        System.out.println("书名、类型、价格、作者");
        Scanner sc= new Scanner(System.in);
        String name = sc.nextLine();
        String type =sc.nextLine();
        int price=sc.nextInt();

        String author =sc.next();

        Book book = new Book(name,type,price,author);

        int currentSize = bookList.getUseSize();
        for (int i = 0; i < currentSize; i++) {
            Book temp = bookList.getBooks(i);
            if(temp.getName().equals(name)) {
                System.out.println("已经有这本书了，添加失败！");
                return;
            }
        }
        bookList.setBooks(book,currentSize);
        bookList.setUseSize(currentSize+1);
        System.out.println("添加成功！");
    }
}
